package com.bstek.test;

import com.bstek.entity.Customer;
import com.bstek.urule.Utils;
import com.bstek.urule.model.ExposeAction;
import com.bstek.urule.runtime.KnowledgePackage;
import com.bstek.urule.runtime.KnowledgeSession;
import com.bstek.urule.runtime.KnowledgeSessionFactory;
import com.bstek.urule.runtime.service.KnowledgeService;
import org.junit.Test;
import org.springframework.stereotype.Component;


///代码调用实例
public class Invoke {

    public void doTest() throws Exception{
        //从Spring中获取KnowledgeService接口实例
        KnowledgeService service=(KnowledgeService) Utils.getApplicationContext().getBean(KnowledgeService.BEAN_ID);
        //通过KnowledgeService接口获取指定的资源包"projectName/test123"
//        KnowledgePackage knowledgePackage=service.getKnowledge("projectName/test123");
        KnowledgePackage knowledgePackage=service.getKnowledge("first/test");
        //通过取到的KnowledgePackage对象创建KnowledgeSession对象
        KnowledgeSession session= KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);

        Customer customer =new Customer();
        customer.setAge(20);
        customer.setHouse(true);
        customer.setLevel(3);

//        Employee employee=new Employee();
//        Dept dept=new Dept();
//        dept.setLevel(12);
//        employee.setDept(dept);
//        employee.setSalary(111000);
        //将业务数据对象Employee插入到KnowledgeSession中
        session.insert(customer);
        //执行所有满足条件的规则
        session.fireRules();

        String result = customer.getName();

        //获取计算后的result值，要通过KnowledgeSession,而不能通过原来的parameter对象
//        boolean result=(Boolean)session.getParameter("result");
//        System.out.println(result);
    }
}
